//
//  Login.m
//  EFExtend
//
//  Created by mac on 15/5/30.
//  Copyright (c) 2015年 Eric. All rights reserved.
//

#import "Login.h"

@interface Login ()

@end

@implementation Login

- (void)dealloc
{
   
    HM_SUPER_DEALLOC();
}

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {
        // Custom initialization
    }
    return self;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
	// Do any additional setup after loading the view.
    
    [self createSubView];

}


- (void)createSubView{
    UIView*image = [[[UIView viewAsImage] EFOwner:self.view]
                    EFImage:[UIImage imageWithContentsOfFile:[HMSandbox pathWithbundleName:nil fileName:@"login/images/user-photo.png"]]];
    [image mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.view.mas_top).offset(25);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.height.mas_equalTo(100);
    }];
    UIView *contain = [[UIView view] EFOwner:self.view];
    contain.tagString = @"contain";
    [contain mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(image.mas_bottom).offset(10);
        make.left.mas_equalTo(self.view.mas_left).offset(0);
        make.height.mas_equalTo(130);
        make.right.mas_equalTo(self.view.mas_right).offset(0);
    }];
    
    UIView *user = [[[[[[UIView viewAsInput] EFOwner:contain]
                       EFLeft:@"login/images/icon100.png"]
                      EFLeftFrame:CGRectMake(5, 15, 30, 30)]
                     EFEdgeInsets:UIEdgeInsetsVerAndLR(0, 40, 0)]
                    EFPlaceText:@"手机号码/邮箱"];
    user.style__ = [HMUIShapeStyle styleWithShape:[HMUIRoundedRectangleShape shapeWithRadius:5] next:[HMUISolidFillStyle styleWithColor:[UIColor md_grey_200] next:nil]];

    [user mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(contain.mas_top).offset(0);
        make.left.mas_equalTo(contain.mas_left).offset(15);
        make.height.mas_equalTo(60);
        make.right.mas_equalTo(contain.mas_right).offset(-15);
    }];
    
    UIView *accessory = [[[UIView viewAsImage]
                          EFFrame:CGRectMake(0, 0, 100, 140)]
                         EFBackgroundColor:[UIColor md_grey_200]];
    
    UIView *password = [[[[[[[UIView viewAsInputTopic]
                             EFLeft:@"login/images/icon100.png"]
                            EFLeftFrame:CGRectMake(5, 15, 30, 30)]
                           EFEdgeInsets:UIEdgeInsetsVerAndLR(0, 40, 0)]
                          EFPlaceText:@"请输入密码"]
                         EFAutoHideKeyboardWhenReturn:YES]
                        EFInputAccessory:accessory];
    password.style__ = [HMUIShapeStyle styleWithShape:[HMUIRoundedRectangleShape shapeWithRadius:5] next:[HMUISolidFillStyle styleWithColor:[UIColor md_grey_200] next:nil]];
    [password EFOwner:contain];
    [password mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(user.mas_bottom).offset(10);
        make.left.mas_equalTo(contain.mas_left).offset(15);
        make.height.mas_equalTo(60);
        make.right.mas_equalTo(contain.mas_right).offset(-15);
    }];
    
    [user EFNextResponder:password];
    
    accessory = [[[UIView viewAsImage]
                          EFFrame:CGRectMake(0, 0, 100, 140)]
                         EFBackgroundColor:[UIColor md_grey_200]];
    
    
    UIView *btn = [[[UIView viewAsButten]
                    EFText:@"登陆"]
                   EFTextFont:[UIFont boldSystemFontOfSize:20]];
    
    btn.style__ = [HMUIShapeStyle styleWithShape:[HMUIRoundedRectangleShape shapeWithRadius:5] next:[HMUISolidFillStyle styleWithColor:[UIColor md_red_400] next:nil]];

    [btn EFOwner:self.view];
    [btn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(contain.mas_bottom).offset(15);
        make.left.mas_equalTo(contain.mas_left).offset(15);
        make.height.mas_equalTo(60);
        make.right.mas_equalTo(contain.mas_right).offset(-15);
    }];
    
    UIView *forget = [[[[UIView viewAsButten]
                        EFText:@"忘记密码?"]
                       EFTextColor:[UIColor md_grey_400]]
                      EFTextFont:[UIFont boldSystemFontOfSize:17]];
    [forget EFOwner:self.view];
    [forget mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(btn.mas_bottom).offset(25);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.height.mas_equalTo(44);
        
    }];
    
    NSString *s = @"没有账号?立即注册";
    NSMutableAttributedString *atts = [[NSMutableAttributedString alloc]initWithString:s];
    NSRange range = NSMakeRange(0, s.length);
    [atts addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:17] range:range];
    [atts addAttribute:NSForegroundColorAttributeName value:[UIColor md_grey_300] range:range];
    range = [s rangeOfString:@"立即注册"];//NSMakeRange(@"没有账号?".length, @"没有账号?立即注册".length);
    [atts addAttribute:NSForegroundColorAttributeName value:[UIColor md_grey_400] range:range];
    
    UIView *signinTip = [[[UIView viewAsButten]
                          EFText:atts]
                         EFTextFont:[UIFont boldSystemFontOfSize:17]];

    [signinTip EFOwner:self.view];
    [signinTip mas_makeConstraints:^(MASConstraintMaker *make) {
        make.bottom.mas_equalTo(self.view.mas_bottom).offset(-25);
        make.centerX.mas_equalTo(self.view.mas_centerX);
        make.height.mas_equalTo(44);
        
    }];
    
    btn.tagString = @"login";
    forget.tagString = @"forget";
    signinTip.tagString = @"signin";
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any res that can be recreated.
}

ON_Button(signal){
    UIButten *btn = signal.source;
    if ([signal is:[UIButten TOUCH_UP_INSIDE]]) {
        if ([btn is:@"leftBtn"]) {//customNavLeftBtn
            [self backAndRemoveWithAnimate:YES];
        }else if ([btn is:@"login"]){
            
        }else if ([btn is:@"forget"]){
            
        }else if ([btn is:@"signin"]){
            
        }
    }
}

ON_TextField(signal){
    HMUITextField *field = signal.source;
    if ([signal is:[HMUITextField WILL_ACTIVE]]) {
        [HMUIKeyboard sharedInstance].visabler = field;
        if ([field.tagString is:@"232"]) {
            [HMUIKeyboard sharedInstance].accessor = field;
        }else{
            [HMUIKeyboard sharedInstance].accessor = [self.view viewWithTagString:@"contain"];
        }
        
    }
}

@end
